<!DOCTYPE html >
<html lang="zh">
<head>
  <title>订单详情</title>
  <{include file="public/header" /}>
  <style>
    .pay{
      width: 45%;float: left;
      margin-top:unset !important;
      margin-left: 10px;
    }
    .mg10-0 {
      margin: 10px 0;
      overflow: hidden;
      text-align: center;
    }
    .orderInfo>p{
      margin-top: 10px;
    }
    .btn-3{
      display: flex;
      flex-direction: column;
      margin-top: 10px !important;
    }
  </style>
</head>
<body ontouchstart>
<!--主体-->
<header class="wy-header">
  <div class="wy-header-icon-back"><span></span></div>
  <div class="wy-header-title">订单详情</div>
</header>
<div class="weui-content">
  <div class="wy-media-box weui-media-box_text address-select">
    <div class="weui-media-box_appmsg">
      <div class="weui-media-box__hd proinfo-txt-l" style="width:20px;"><span class="promotion-label-tit">
        <img src="/static/mall/images/icon_nav_city.png" /></span></div>
      <div class="weui-media-box__bd">
        <a href=""  class="weui-cell_access addr">
          <h4 class="address-name"><span class="addr-username"></span><span class="addr-mobile"></span></h4>
          <div class="address-txt addr-detail"></div>
        </a>
      </div>
      <div class="weui-media-box__hd proinfo-txt-l" style="width:16px;"><div class="weui-cell_access"></div></div>
    </div>
  </div>
  <div class="wy-media-box weui-media-box_text">
    <div class="weui-media-box__bd " id="pro-list"></div>
  </div>
  <div class="wy-media-box weui-media-box_text">
    <div class="mg10-0 t-c">总金额：<span class="wy-pro-pri mg-tb-5">¥<em class="num font-20 totalMoney">0.00</em></span></div>
    <div class="mg10-0 btn-div">
      <a href="javascript:create('wechat')" class="weui-btn weui-btn_primary pay pay-wechat">微信付款</a>
      <a href="javascript:create('alipay')" class="weui-btn pay pay-alipay" style="display: none;background-color: #1111e0a8">支付宝</a>
      <a href="javascript:create('credit')" class="weui-btn weui-btn_default pay pay-credit">余额支付</a>
      <div id="alipay-form" style="display: none"></div>
    </div>
  </div>
  <div class="wy-media-box weui-media-box_text orderInfo" style="display: none">

  </div>
  <div class="wy-media-box weui-media-box_text action_div"  >

  </div>
</div>
<{include file="public/footer" /}>
<{include file="public/weixin_jsapi" /}>
<{include file="public/_info_js" /}>

<script>
  var order_sn = bs_get_param('order_sn');
  var shop_tel = null;
  $(function () {
    var shop_config = JSON.parse(localStorage.getItem('config_shop'));
    if (shop_config.shop_tel){
      shop_tel = shop_config.shop_tel
    }
    if (shop_config.pay_wechat===1){
      $(".pay-wechat").show();
    }else {
      $(".pay-wechat").hide();
    }
    if (shop_config.pay_credit===1){
      $(".pay-credit").show();
    }else {
      $(".pay-credit").hide();
    }
    if (shop_config.pay_wechat===1 && shop_config.pay_credit===1){
      $(".pay").addClass('btn-2')
    }
    if (shop_config.pay_alipay===1){
      $(".pay-alipay").show();
    }

    if (shop_config.pay_wechat===1 && shop_config.pay_credit===1 && shop_config.pay_alipay===1){
      $(".pay").removeClass('btn-2').addClass('btn-3');
    }
  })
  getData();
  function getData() {
    bs_request("<{:url('/mall/order/detail')}>",{order_sn:order_sn,},function (res) {
      if (res.code != 0){
        return $.alert(res.msg);
      }
      $(".addr").attr('href',"javascript:void(0)")
      if (res.data.address){
        $(".addr-username").html(res.data.address.username);
        $(".addr-mobile").html(res.data.address.mobile);
        $(".addr-detail").html(res.data.address.province+' '+res.data.address.city+' '+res.data.address.area+' '+res.data.address.address);
      }else {
        $(".address-select").remove();

      }
      var goods = res.data.goods_list;

      for (var i=0;i<goods.length;i++){
        var item = ' <div class="weui-media-box_appmsg ord-pro-list">\n' +
                '        <div class="weui-media-box__hd"><a href="<{:url(\'/mall/goods/detail\')}>?id='+goods[i].goods_id+'"><img class="weui-media-box__thumb" src="'+goods[i].thumb+'" alt=""></a></div>\n' +
                '        <div class="weui-media-box__bd">\n' +
                '          <h1 class="weui-media-box__desc"><a href="<{:url(\'/mall/goods/detail\')}>?id='+goods[i].goods_id+'" class="ord-pro-link">'+goods[i].title+'</a></h1>\n' +
                '          <!--<p class="weui-media-box__desc">规格：<span>红色</span>，<span>23</span></p>-->\n' +
                '          <div class="clear mg-t-10">\n' +
                '            <div class="wy-pro-pri fl">¥<em class="num font-15">'+goods[i].price+'</em></div>\n' +
                '            <div class="pro-amount fr"><span class="font-13">数量×<em class="name">'+goods[i].count+'</em></span></div>\n' +
                '          </div>\n' +
                '        </div>\n' +
                '      </div>';


        $("#pro-list").append(item)
      }

      var order = res.data.order;

      var orderItem = '<p class="weui-media-box__hd" >订单：<span onclick="copy(this)">'+order.order_sn+'</span></p>';
      orderItem += '<p class="weui-media-box__hd">下单时间：'+order.add_time+'</p>';
      if (order.pay_time!=0){
        orderItem += '<p class="weui-media-box__hd">支付时间：'+order.pay_time+' </p>';
        if (order.send_time!=0){
          orderItem += '<p class="weui-media-box__hd">发货时间：'+order.send_time+' </p>';
        }
        var payType = '其它';
        if (order.pay_type=='credit'){
          payType = '余额'
        }else if(order.pay_type=='wechat'){
          payType = '微信'
        }else if(order.pay_type=='alipay'){
          payType = '支付宝'
        }
        orderItem += '<p class="weui-media-box__hd">支付方式：'+payType+'</p>';

      }

      if (order.receive_time!=0){
        orderItem += '<p class="weui-media-box__hd">收货时间：'+order.receive_time+' </p>';
      }
      if (order.pay_price>0){
        orderItem += '<p class="weui-media-box__hd">实付：<span style="color:red;">'+order.pay_price+'</span> 元</p>';
      }
      if (order.coupon_money>0){
        orderItem += '<p class="weui-media-box__hd">优惠抵扣：<span style="color:red;">'+order.coupon_money+'</span> 元（原价'+order.old_money+'）</p>';
      }
      if (order.refund_total>0){
        orderItem += '<p class="weui-media-box__hd">累计退款：<span style="color:red;">'+order.refund_total+'</span> 元</p>';
      }
      if (order.code_tihuo){
        orderItem += '<p class="weui-media-box__hd" >提货码：<span onclick="copy(this)">'+order.code_tihuo+'</span> </p>';
      }
      //待支付、待发货时可以备注给商家
      if (order.status===1 || order.status===0){
        orderItem += '<p class="weui-cell__bd">订单备注： <input onclick="showRemarkBox()"  id="remark" autocomplete="off" placeholder="点击添加订单备注" value="'+order.remark+'"/> </p>';
      }else if(order.remark){
        orderItem += '<p class="weui-cell__bd">订单备注：<span style="color: #f16262"> '+order.remark+' </span></p>';
      }

      if (res.data.store_info && shop_tel){
        orderItem += '<p class="weui-media-box__hd" ><span class="to-contact weui-btn  weui-btn_mini weui-btn_plain-primary" >联系卖家</span> </p>';
      }

      var actionBtns='';

      if(order.status==1){

        if (order.order_type==2){
          actionBtns+='<div class="tihuo-address" ><b>提货地址</b>：<span onclick="copy(this)">'+order.tihuo_address+'</span></div>';
          actionBtns+='提货码：<span onclick="copy(this,false,1500)" class="tihuo-code">'+order.code_tihuo+'</span>';
          actionBtns+='<a href="javascript:;" class="ords-btn-com receipt " data-sn="'+order.order_sn+'">确认取货</a>';
        }else {
          actionBtns+='商品正在打包中，请您耐心等待....';
        }
        actionBtns+='<a href="javascript:;" class="ords-btn-com refund" data-sn="'+order.order_sn+'">申请退款</a>';
      }else if(order.status==2){
        if (order.order_type==3){
          actionBtns+='<a href="<{:url(\'/mall/order/virtual\')}>?order_sn='+order.order_sn+'" class="ords-btn-com " data-sn="'+order.order_sn+'">查看发货</a>';
          actionBtns+='<a href="javascript:;" class="ords-btn-com receipt" data-sn="'+order.order_sn+'">确认收货</a>';
        }else {

          actionBtns+='<a href="javascript:;" class="ords-btn-com receipt" data-sn="'+order.order_sn+'">确认收货</a>';

        }

      }else if(order.status==3){
        if (order.order_type==3){
          actionBtns+='<a href="<{:url(\'/mall/order/virtual\')}>?order_sn='+order.order_sn+'" class="ords-btn-com " data-sn="'+order.order_sn+'">查看发货</a>';
        }
        actionBtns+=' <a href="<{:url(\'/mall/order/detail2\')}>?order_sn='+order.order_sn+'" class="ords-btn-com" data-sn="'+order.order_sn+'">评价</a>';
      }else if (order.status=='-1'){
        actionBtns+='<a href="javascript:;" class="ords-btn-dele" data-sn="'+order.order_sn+'">删除订单</a>';
      }else{
        if (order.order_type==3){
          actionBtns+='<a href="<{:url(\'/mall/order/virtual\')}>?order_sn='+order.order_sn+'" class="ords-btn-com " data-sn="'+order.order_sn+'">查看发货</a>';
        }


      }
      if (order.express_no){
        actionBtns+='<a href="<{:url(\'/mall/order/express\')}>?order_sn='+order.order_sn+'" class="ords-btn-com express" data-sn="'+order.order_sn+'">查看物流</a>';
      }
      if (actionBtns.length>0){
        $(".action_div").html(actionBtns)
      }

      $(".orderInfo").show();
      $(".orderInfo").html(orderItem)

      if (order.status !=0){
        $(".btn-div").hide()
      }
      $(".totalMoney").text(order.price);

    });
  }
  $(document).on("click", ".refund", function() {
    var ordersn = $(this).data('sn')
    location.href = "<{:url('/mall/order/refund')}>?order_sn="+ordersn
  });
  $(document).on('click','.to-contact',function () {
    if (shop_tel){
      $.confirm('是否现在拨打商家电话联系？',function () {
        location.href = "tel:"+shop_tel
      })
    }else {
      $.alert('商家未配置联系方式')
    }

  });

  function showRemarkBox() {
    $.prompt({
      text: '请下下面输入您与商家协商后的内容',
      title: '添加订单备注',
      onOK: function (remark) {
        bs_request("<{:url('/mall/order/add_remark')}>",{order_sn:order_sn,remark:remark},function (res) {
          $.toast(res.msg,res.code==0?'success':'cancel',1000);
          if (res.code==0){
            location.reload()
          }
        })
      },
      onCancel: function () {
      }
    })
  }
  $(document).on("click", ".ords-btn-dele", function() {
    var order_sn = $(this).data('sn');
    $.confirm("您确定要删除此订单吗?", "确认删除?", function() {

      bs_request("<{:url('/mall/order/del')}>",{order_sn:order_sn},function (res) {

        $.toast(res.msg,res.code==0?'success':'cancel',1000);
        if (res.code==0){
          $(".order-item-"+order_sn).remove()
        }
      })
    }, function() {
      //取消操作
    });
  });

  $(document).on("click", ".receipt", function() {
    var order_sn = $(this).data('sn');
    $.confirm("您已经收到货了吗", "是否已经收到货?", function() {

      bs_request("<{:url('/mall/order/receive')}>",{order_sn:order_sn},function (res) {

        //$.toast(res.msg,res.code==0?'success':'cancel');
        if (res.code==0){
          $.alert("好东西记得五星好评哦，赶快去评价吧！", "收货完成！",function (res) {
            location.href = "<{:url('/mall/order/detail2')}>?order_sn="+order_sn
          });
        }else {
          $.toast(res.msg,'cancel');
        }
      })
    }, function() {
      //取消操作
    });


  });


  function create(type) {
    return start_pay(type, {order_sn: order_sn, payType: type})
  }
</script>
</body>
</html>
